﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Configuration;
using System.Data;

namespace Demog {
    class ExcelReader {
        private static string baseCs =
            "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=\"Excel 8.0;HDR=YES\";";
        
        private OleDbConnection connection;
        
        public ExcelReader(string fileName) {
             string cs = baseCs + "Data Source=" + fileName;
            
            connection = new OleDbConnection(cs);
        }

        public DataSet ReadData() {
            connection.Open();
            OleDbCommand command = new OleDbCommand("SELECT * FROM [Лист1$]", connection);
            OleDbDataAdapter adapter = new OleDbDataAdapter();
            adapter.SelectCommand = command;
            DataSet ds = new DataSet();
            adapter.Fill(ds);
            connection.Close();
            return ds;  
        }
    }
}